/**
 * 
 */
package yanivosher.aiproject;

import java.util.LinkedList;

/**
 * @author Yaniv n Osher
 * 
 */
public class GreedyAgent extends Agent {

	public GreedyAgent(Vertex currentVertex, Vertex destinationVertex) {
		super(currentVertex, destinationVertex);
	}

	public Step makeAmove(Graph curr) {
		System.out.println("Making a greedy step ");

		Step step = new Step();
		step.setCurrent(currentVertex);
		step.setMilitary(false);
		if ((currentVertex.getChem()) > 0) {
			step.setChem(true);
		} else
			step.setChem(false);
		// Generates the wanted step through Dijkstra algorithm
		DijkstraAlgorithm dAlgorithm = new DijkstraAlgorithm(Environment
				.getInstance().graph.omittedBlockedGraph());
		dAlgorithm.execute(currentVertex);
		LinkedList<Vertex> trip = dAlgorithm.getPath(destinationVertex);
		if (trip == null) {

			System.out.println("Dijkstra trip null! ");
			step.setDestination(currentVertex);
		}
		else
		{
			if (trip.size() > 1) {
				step.setDestination(trip.get(1));
			}
			else
			{
				step.setDestination(trip.getFirst());
			}
		}
		return step;
	}

	@Override
	public boolean idDone() {
		return currentVertex.equals(destinationVertex);
	}
	
}
